# coding=utf-8

from datetime import timedelta
from app.config import config
from flask import Flask
from flask_bootstrap import Bootstrap
from flask_mongoengine import MongoEngine
from flask_login import LoginManager

database = MongoEngine()
bootstrap = Bootstrap()
log_manager = LoginManager()

def create_app():
    """create A new Flask app

    You can return a class of Flask types by calling this function.

    Args:
        None
    Returns:
        A class of Flask

    """
    app = Flask(__name__)

    # register all config
    app.config.from_object(config['debug'])

    # register all extensions
    database.init_app(app)
    bootstrap.init_app(app)
    log_manager.init_app(app)

    # register blueprint

    # the Settings for login
    log_manager.login_view = 'login.index'
    log_manager.login_message = 'Plase Login First !'
    log_manager.session_protection = 'strong'
    log_manager.remember_cookie_duration = timedelta(days=1)

    return app
